package com.itcast.tanhuaserver.service.impl;

import com.alibaba.dubbo.config.annotation.Reference;
import com.itcast.tanhua.dubbo.server.api.RecommendUserApi;
import com.itcast.tanhua.dubbo.server.domain.RecommendUser;
import com.itcast.tanhua.dubbo.server.vo.PageInfo;
import com.itcast.tanhuaserver.service.RecommendUserService;
import com.itcast.tanhuaserver.vo.TodayBest;
import org.springframework.stereotype.Service;

/**
 * @PachageName: com.itcast.tanhuaserver.service.impl
 * @ClassName:
 * @Description: TODO
 * @Author: Hushi
 * @DateTime: 2021/2/1610:20
 * @Version 1.0
 */
@Service
public class RecommendUserServiceImpl implements RecommendUserService {
    @Reference(version = "1.0.0")
    private RecommendUserApi recommendUserApi;

    @Override
    public TodayBest queryTodayBest(Long userId) {
        RecommendUser recommendUser = this.recommendUserApi.queryWithMaxScore(userId);
        if (recommendUser == null){
            return null;
        }
        TodayBest todayBest = new TodayBest();
        todayBest.setId(recommendUser.getUserId());
        //缘分值
        double score = Math.floor(recommendUser.getScore());//取整,98.2 -> 98
        todayBest.setFateValue(Double.valueOf(score).longValue());
        return todayBest;
    }

    @Override
    public PageInfo<RecommendUser> queryRecommendUserList(Integer userId, Integer page, Integer pagesize) {
        return this.recommendUserApi.queryPageInfo(userId.longValue(), page, pagesize);
    }

    /**
     * 查询推荐好友的缘分值
     *
     * @param userId
     * @param toUserId
     * @return
     */
    @Override
    public double queryScore(Long userId, Long toUserId) {
        return this.recommendUserApi.queryScore(userId,toUserId);
    }
}
